Is it possible to create a text file in python?
1. Yes
2.No
3.Machine dependent
4. All of the mentioned
Posted Date:-2022-01-02 11:19:54
Is the following Python code valid? class B(object): def first(self): print("First method called") def second(): print("Second method called") ob = B() B.first(ob)
1.It isn’t as the object declaration isn’t right
2. It isn’t as there isn’t any __init__ method for initializing class members
3. Yes, this method of calling is called unbounded method call
4.Yes, this method of calling is called bounded method call
Posted Date:-2022-01-02 11:48:18
What does print(Test.__name__) display (assuming Test is the name of the class)?
1. ()
2.Exception is thrown
3.Test
4.__main__
Posted Date:-2022-01-02 11:51:57
What is getattr() used for?
1.To access the attribute of the object
2. To delete an attribute
3.To check if an attribute exists or not
4.To set an attribute
Posted Date:-2022-01-02 11:43:47
What will be the output of the following Python code? class Demo: def __init__(self): pass def test(self): print(__name__) obj = Demo() obj.test()
1. Exception is thrown
2.__main__
3.Demo
4. test
Posted Date:-2022-01-02 11:46:40
What will be the output of the following Python code? >>> class demo(): def __repr__(self): return '__repr__ built-in function called' def __str__(self): return '__str__ built-in function called' >>> s=demo() >>> print(s)
1. Error
2.Nothing is printed
3. __str__ called
4. __repr__ called
Posted Date:-2022-01-02 11:49:11
What will be the output of the following Python code? class fruits: def __init__(self, price): self.price = price obj=fruits(50) obj.quantity=10 obj.bags=2 print(obj.quantity+len(obj.__dict__))
1. 12
2. 52
3. 13
4.60
Posted Date:-2022-01-02 11:46:12
What will be the output of the following Python code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): Test.__init__(self) self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main()
1.Error because class B inherits A but variable x isn’t inherited
2.0 0
3.0 1
4.Error, the syntax of the invoking method is wrong
Posted Date:-2022-01-02 11:55:17
Which function overloads the == operator?
1.__eq__()
2.__equ__()
3. __isequal__()
4.none of the mentioned
Posted Date:-2022-01-02 11:28:44
How do you change the file position to an offset value from the start?
1. fp.seek(offset, 0)
2. fp.seek(offset, 1)
3.fp.seek(offset, 2)
4.none of the mentioned
Posted Date:-2022-01-02 11:26:27
How do you close a file object (fp)?
1.close(fp)
2.fclose(fp)
3.fp.close()
4. fp.__close__()
Posted Date:-2022-01-02 11:24:51
How do you delete a file?
1.del(fp)
2. fp.delete()
3.os.remove(‘file’)
4. os.delete(‘file’)
Posted Date:-2022-01-02 11:26:04
How do you get the current position within the file?
1. fp.seek()
2. fp.tell()
3.fp.loc
4. fp.pos
Posted Date:-2022-01-02 11:25:16
How do you get the name of a file from a file object (fp)?
1. fp.name
2. fp.file(name)
3.self.__name__(fp)
4.fp.__name__()
Posted Date:-2022-01-02 11:24:00
How do you rename a file?
1. fp.name = ‘new_name.txt’
2.os.rename(existing_name, new_name)
3.os.rename(fp, new_name)
4.os.set_name(existing_name, new_name)
Posted Date:-2022-01-02 11:25:41
Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
1.__add__(), __str__()
2. __str__(), __add__()
3.__sum__(), __str__()
4.__str__(), __sum__()
Posted Date:-2022-01-02 11:30:28
Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?
1. A.__init__(self)
2.B.__init__(self)
3.A.__init__(B)
4.B.__init__(A)
Posted Date:-2022-01-02 11:54:44
The assignment of more than one function to a particular operator is _____
1.Operator over-assignment
2.Operator overriding
3.Operator overloading
4. Operator instance
Posted Date:-2022-01-02 11:47:25
What are the methods which begin and end with two underscore characters called?
1.Special methods
2.In-built methods
3.User-defined methods
4.Additional methods
Posted Date:-2022-01-02 11:48:38
What happens if no arguments are passed to the seek function?
1. file position is set to the start of file
2.file position is set to the end of file
3.file position remains unchanged
4. error
Posted Date:-2022-01-02 11:26:52
What is delattr(obj,name) used for?
1. To print deleted attribute
2.To delete an attribute
3.To check if an attribute is deleted or not
4.To set an attribute
Posted Date:-2022-01-02 11:51:07
What is hasattr(obj,name) used for?
1.To access the attribute of the object
2.To delete an attribute
3. To check if an attribute exists or not
4. To set an attribute
Posted Date:-2022-01-02 11:50:15
What is Instantiation in terms of OOP terminology?
1. Deleting an instance of class
2.Modifying an instance of class
3.Copying an instance of class
4.Creating an instance of class
Posted Date:-2022-01-02 11:45:42
What is setattr() used for?
1. To access the attribute of the object
2.To set an attribute
3.To check if an attribute exists or not
4.To delete an attribute
Posted Date:-2022-01-02 11:43:25
What is the difference between r+ and w+ modes?
1.no difference
2.in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
3.in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
4.depends on the operating system
Posted Date:-2022-01-02 11:23:35
What will be the output of the following Python code? class test: def __init__(self,a): self.a=a def display(self): print(self.a) obj=test() obj.display()
1.Runs normally, doesn’t display anything
2.Displays 0, which is the automatic default value
3.Error as one argument is required while creating the object
4.Error as display function requires additional argument
Posted Date:-2022-01-02 11:44:38
What will be the output of the following Python code? >>> class demo(): def __repr__(self): return '__repr__ built-in function called' def __str__(self): return '__str__ built-in function called' >>> s=demo() >>> print(s)
1. __str__ called
2.__repr__ called
3.Error
4.Nothing is printed
Posted Date:-2022-01-02 11:49:42
What will be the output of the following Python code? class A(): def disp(self): print("A disp()") class B(A): pass obj = B() obj.disp()
1.invalid syntax for inheritance
2.Error because when object is created, argument must be passed
3.Nothing is printed
4.A disp()
Posted Date:-2022-01-02 11:54:16
What will be the output of the following Python code? class change: def __init__(self, x, y, z): self.a = x + y + z x = change(1,2,3) y = getattr(x, 'a') setattr(x, 'a', y+1) print(x.a)
1. 6
2. 7
3. Error
4. 0
Posted Date:-2022-01-02 11:44:12
What will be the output of the following Python code? class stud: ‘Base class for all students’ def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) print(student.__doc__)
1.Exception is thrown
2.__main__
3.Nothing is displayed
4.Base class for all students
Posted Date:-2022-01-02 11:51:32
What will be the output of the following Python code? class stud: def __init__(self, roll_no, grade): self.roll_no = roll_no self.grade = grade def display (self): print("Roll no : ", self.roll_no, ", Grade: ", self.grade) stud1 = stud(34, 'S') stud1.age=7 print(hasattr(stud1, 'age'))
1.Error as age isn’t defined
2. True
3. False
4.7
Posted Date:-2022-01-02 11:50:41
What will be the output of the following Python code? class test: def __init__(self): self.variable = 'Old' self.Change(self.variable) def Change(self, var): var = 'New' obj=test() print(obj.variable)
1.Error because function change can’t be called in the __init__ function
2. ‘New’ is printed
3.‘Old’ is printed
4.Nothing is printed
Posted Date:-2022-01-02 11:45:15
What will be the output of the following Python code? class test: def __init__(self,a="Hello World"): self.a=a def display(self): print(self.a) obj=test() obj.display()
1. The program has an error because constructor can’t have default arguments
2.Nothing is displayed
3. “Hello World†is displayed
4.The program has an error display function doesn’t have parameters
Posted Date:-2022-01-02 11:42:58
What will be the output of the following Python code? class Test: def __init__(self): self.x = 0 class Derived_Test(Test): def __init__(self): self.y = 1 def main(): b = Derived_Test() print(b.x,b.y) main()
1.0 1
2. 0 0
3.Error because class B inherits A but variable x isn’t inherited
4.Error because when object is created, argument must be passed like Derived_Test(1)
Posted Date:-2022-01-02 11:53:53
Which function is called when the following Python code is executed? f = foo() format(f)
1. format()
2. __format__()
3.str()
4.__str__()
Posted Date:-2022-01-02 11:27:30
Which function is used to close a file in python?
1.Close()
2.Stop()
3.End()
4.Closefile()
Posted Date:-2022-01-02 11:19:33
Which function overloads the >> operator?
1.__more__()
2. __gt__()
3.__ge__()
4.none of the mentioned
Posted Date:-2022-01-02 11:30:04
Which function overloads the + operator?
1. __add__()
2.__plus__()
3. __sum__()
4.none of the mentioned
Posted Date:-2022-01-02 11:27:59
Which function overloads the // operator?
1. __div__()
2._ceildiv__()
3. __floordiv__()
4.__truediv__()
Posted Date:-2022-01-02 11:31:16
Which of the following are the modes of both writing and reading in binary format in file?
1. wb+
2.w
3.wb
4.w+
Posted Date:-2022-01-02 11:20:18
Which of the following best describes inheritance?
1.Ability of a class to derive members of another class as a part of its own definition
2.Means of bundling instance variables and methods in order to restrict access to certain class members
3.Focuses on variables and passing of variables to functions
4.Allows for implementation of elegant software that is well designed and easily modified
Posted Date:-2022-01-02 11:52:42
Which of the following is not a class method?
1.Non-static
2. Static
3.Bounded
4.unbounded solution
Posted Date:-2022-01-02 11:47:47
Which of the following is not a valid attribute of a file object (fp)?
1. fp.name
2. fp.closed
3.fp.mode
4.fp.size
Posted Date:-2022-01-02 11:24:25
Which of the following is not a valid mode to open a file?
1.ab
2. rw
3.r+
4. w+
Posted Date:-2022-01-02 11:23:09
Which of the following statements is wrong about inheritance?
1. Protected members of a class can be inherited
2.The inheriting class is called a subclass
3.Private members of a class can be inherited and accessed
4.Inheritance is one of the features of OOP
Posted Date:-2022-01-02 11:53:06
Which operator is overloaded by the __or__() function?
1.||
2. |
3.//
4./
Posted Date:-2022-01-02 11:30:52
Which operator is overloaded by __invert__()?
1. !
2. ~
3.^
4.–
Posted Date:-2022-01-02 11:28:20
Which operator is overloaded by __lg__()?
1.<
2. >
3. !=
4.none of the mentioned
Posted Date:-2022-01-02 11:29:05
____ is used to create an object.
1.class
2.constructor
3.User-defined functions
4. In-built functions
Posted Date:-2022-01-02 11:32:13
_____ represents an entity in the real world with its identity and behaviour.
1. A method
2.An object
3. A class
4. An operator
Posted Date:-2022-01-02 11:31:47